{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bedrock ModelBuilder Example\n"
   ]
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "# Configure AWS credentials and region\n",
    "#! ada credentials update --provider=isengard --account=<> --role=Admin --profile=default --once\n",
    "#! aws configure set region us-west-2"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Setup\n",
    "import boto3\n",
    "import json\n",
    "import time\n",
    "import random\n",
    "from sagemaker.core.resources import TrainingJob\n",
    "from sagemaker.serve.bedrock_model_builder import BedrockModelBuilder"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Configuration\n",
    "TRAINING_JOB_NAME = 'meta-textgeneration-llama-3-2-1b-instruct-sft-20251123162832'\n",
    "ROLE_ARN = \"arn:aws:iam::<>:role/Admin\"\n",
    "REGION = 'us-west-2'\n",
    "BUCKET = 'open-models-testing-pdx'"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Step 1: Get training job and prepare model path\n",
    "training_job = TrainingJob.get(training_job_name=TRAINING_JOB_NAME)\n",
    "print(f\"Training job status: {training_job.training_job_status}\")\n",
    "\n",
    "# Use the hf_merged directory which has complete HuggingFace format\n",
    "base_s3_path = training_job.model_artifacts.s3_model_artifacts\n",
    "hf_model_path = base_s3_path.rstrip('/') + '/checkpoints/hf_merged/'\n",
    "print(f\"Using HF model path: {hf_model_path}\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Step 2: Verify required files exist\n",
    "s3_client = boto3.client('s3', region_name=REGION)\n",
    "\n",
    "required_files = ['config.json', 'tokenizer.json', 'tokenizer_config.json', 'model.safetensors']\n",
    "model_prefix = hf_model_path.replace(f's3://{BUCKET}/', '')\n",
    "\n",
    "print(\"Checking required files:\")\n",
    "for file in required_files:\n",
    "    try:\n",
    "        s3_client.head_object(Bucket=BUCKET, Key=model_prefix + file)\n",
    "        print(f\"✅ {file}\")\n",
    "    except:\n",
    "        print(f\"❌ {file} - MISSING\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Step 3: Create missing tokenizer files if needed\n",
    "def ensure_tokenizer_files():\n",
    "    # Create added_tokens.json (usually empty for Llama)\n",
    "    try:\n",
    "        s3_client.head_object(Bucket=BUCKET, Key=model_prefix + 'added_tokens.json')\n",
    "        print(\"✅ added_tokens.json exists\")\n",
    "    except:\n",
    "        s3_client.put_object(\n",
    "            Bucket=BUCKET,\n",
    "            Key=model_prefix + 'added_tokens.json',\n",
    "            Body=json.dumps({}),\n",
    "            ContentType='application/json'\n",
    "        )\n",
    "        print(\"✅ Created added_tokens.json\")\n",
    "\n",
    "ensure_tokenizer_files()"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Debug: Check what's actually in the S3 bucket\n",
    "print(\"Checking S3 structure...\")\n",
    "base_prefix = base_s3_path.replace(f's3://{BUCKET}/', '')\n",
    "print(f\"Base prefix: {base_prefix}\")\n",
    "\n",
    "# List files to see the actual structure\n",
    "response = s3_client.list_objects_v2(\n",
    "    Bucket=BUCKET,\n",
    "    Prefix=base_prefix,\n",
    "    Delimiter='/'\n",
    ")\n",
    "\n",
    "print(\"Contents:\")\n",
    "if 'Contents' in response:\n",
    "    for obj in response['Contents'][:10]:  # Show first 10 files\n",
    "        print(f\"  {obj['Key']}\")\n",
    "\n",
    "# Check specifically for hf_merged directory\n",
    "hf_merged_prefix = base_prefix.rstrip('/') + '/checkpoints/hf_merged/'\n",
    "print(f\"\\nChecking hf_merged path: {hf_merged_prefix}\")\n",
    "\n",
    "try:\n",
    "    response = s3_client.list_objects_v2(Bucket=BUCKET, Prefix=hf_merged_prefix)\n",
    "    if 'Contents' in response:\n",
    "        print(\"Files in hf_merged:\")\n",
    "        for obj in response['Contents']:\n",
    "            file_name = obj['Key'].replace(hf_merged_prefix, '')\n",
    "            print(f\"  {file_name}\")\n",
    "            \n",
    "        # Now copy with correct paths\n",
    "        for obj in response['Contents']:\n",
    "            source_key = obj['Key']\n",
    "            file_name = source_key.replace(hf_merged_prefix, '')\n",
    "            dest_key = base_prefix.rstrip('/') + '/' + file_name\n",
    "            \n",
    "            try:\n",
    "                s3_client.copy_object(\n",
    "                    Bucket=BUCKET,\n",
    "                    CopySource={'Bucket': BUCKET, 'Key': source_key},\n",
    "                    Key=dest_key\n",
    "                )\n",
    "                print(f\"✅ Copied {file_name}\")\n",
    "            except Exception as e:\n",
    "                print(f\"❌ Failed to copy {file_name}: {e}\")\n",
    "    else:\n",
    "        print(\"No files found in hf_merged directory\")\n",
    "except Exception as e:\n",
    "    print(f\"Error: {e}\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Step 4: Create Bedrock model builder and deploy\n",
    "job_name = f\"bedrock-import-{random.randint(1000, 9999)}-{int(time.time())}\"\n",
    "print(f\"Job name: {job_name}\")\n",
    "\n",
    "# Create builder with correct model path\n",
    "bedrock_builder = BedrockModelBuilder(\n",
    "    model=training_job\n",
    ")\n",
    "\n",
    "# Deploy to Bedrock\n",
    "deployment_result = bedrock_builder.deploy(\n",
    "    job_name=job_name,\n",
    "    imported_model_name=job_name,\n",
    "    role_arn=ROLE_ARN\n",
    ")\n",
    "\n",
    "job_arn = deployment_result['jobArn']\n",
    "print(f\"Import job started: {job_arn}\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Step 5: Wait for import to complete\n",
    "bedrock_client = boto3.client('bedrock', region_name=REGION)\n",
    "\n",
    "print(\"Waiting for import to complete...\")\n",
    "while True:\n",
    "    response = bedrock_client.get_model_import_job(jobIdentifier=job_arn)\n",
    "    status = response['status']\n",
    "    print(f\"Status: {status}\")\n",
    "    \n",
    "    if status == 'Completed':\n",
    "        imported_model_arn = response['importedModelArn']\n",
    "        print(f\"✅ Import completed!\")\n",
    "        print(f\"Model ARN: {imported_model_arn}\")\n",
    "        break\n",
    "    elif status in ['Failed', 'Stopped']:\n",
    "        print(f\"❌ Import failed: {status}\")\n",
    "        if 'failureMessage' in response:\n",
    "            print(f\"Error: {response['failureMessage']}\")\n",
    "        break\n",
    "    \n",
    "    time.sleep(30)"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Step 6: Test inference with correct format\n",
    "if 'imported_model_arn' in locals():\n",
    "    bedrock_runtime = boto3.client('bedrock-runtime', region_name=REGION)\n",
    "    \n",
    "    # Try ChatCompletion format (OpenAI-style)\n",
    "    try:\n",
    "        response = bedrock_runtime.invoke_model(\n",
    "            modelId=imported_model_arn,\n",
    "            body=json.dumps({\n",
    "                \"messages\": [\n",
    "                    {\"role\": \"user\", \"content\": \"What is the capital of France?\"}\n",
    "                ],\n",
    "                \"max_tokens\": 100,\n",
    "                \"temperature\": 0.7\n",
    "            })\n",
    "        )\n",
    "        \n",
    "        result = json.loads(response['body'].read().decode())\n",
    "        print(\"\\n🎉 Inference successful (ChatCompletion format)!\")\n",
    "        print(f\"Response: {result}\")\n",
    "        \n",
    "    except Exception as e1:\n",
    "        print(f\"ChatCompletion failed: {e1}\")\n",
    "        \n",
    "        # Try BedrockMetaCompletion format\n",
    "        try:\n",
    "            response = bedrock_runtime.invoke_model(\n",
    "                modelId=imported_model_arn,\n",
    "                body=json.dumps({\n",
    "                    \"prompt\": \"What is the capital of France?\",\n",
    "                    \"max_gen_len\": 100,\n",
    "                    \"temperature\": 0.7,\n",
    "                    \"top_p\": 0.9\n",
    "                })\n",
    "            )\n",
    "            \n",
    "            result = json.loads(response['body'].read().decode())\n",
    "            print(\"\\n🎉 Inference successful (BedrockMeta format)!\")\n",
    "            print(f\"Response: {result}\")\n",
    "            \n",
    "        except Exception as e2:\n",
    "            print(f\"BedrockMeta failed: {e2}\")\n",
    "            print(\"❌ Both formats failed. Check model documentation for correct format.\")\n",
    "else:\n",
    "    print(\"❌ Import failed, cannot test inference\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Optional: List all imported models\n",
    "models = bedrock_client.list_imported_models()\n",
    "print(\"\\nAll imported models:\")\n",
    "for model in models['modelSummaries']:\n",
    "    print(f\"- {model['modelName']}: {model['modelArn']}\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-27T01:09:24.972978Z",
     "start_time": "2025-11-27T01:09:18.454635Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from pprint import pprint\n",
    "from sagemaker.core.resources import TrainingJob\n",
    "from sagemaker.serve.bedrock_model_builder import BedrockModelBuilder\n",
    "\n",
    "training_job = TrainingJob.get(training_job_name=\"kssharda-sft-lora-lite-2-ui-run-2bn3c-<>8\",\n",
    "                               region=\"us-east-1\")\n",
    "pprint(training_job.model_artifacts.s3_model_artifacts)\n"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m[11/26/25 17:09:22]\u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m Found credentials in shared credentials file: ~\u001B[38;2;225;0;225m/.aws/\u001B[0m\u001B[38;2;225;0;225mcredentials\u001B[0m   \u001B]8;id=147201;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py\u001B\\\u001B[2mcredentials.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=746538;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py#1392\u001B\\\u001B[2m1392\u001B[0m\u001B]8;;\u001B\\\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[11/26/25 17:09:22] </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> Found credentials in shared credentials file: ~<span style=\"color: #e100e1; text-decoration-color: #e100e1\">/.aws/credentials</span>   <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">credentials.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py#1392\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">1392</span></a>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml\n",
      "sagemaker.config INFO - Not applying SDK defaults from location: /Users/nargokul/Library/Application Support/sagemaker/config.yaml\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m[11/26/25 17:09:24]\u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m Runs on sagemaker us-east-\u001B[1;36m1\u001B[0m, region:us-east-\u001B[1;36m1\u001B[0m                             \u001B]8;id=46858;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-core/src/sagemaker/core/utils/utils.py\u001B\\\u001B[2mutils.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=786052;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-core/src/sagemaker/core/utils/utils.py#354\u001B\\\u001B[2m354\u001B[0m\u001B]8;;\u001B\\\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[11/26/25 17:09:24] </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> Runs on sagemaker us-east-<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>, region:us-east-<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>                             <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-core/src/sagemaker/core/utils/utils.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">utils.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-core/src/sagemaker/core/utils/utils.py#354\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">354</span></a>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m                   \u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m Found credentials in shared credentials file: ~\u001B[38;2;225;0;225m/.aws/\u001B[0m\u001B[38;2;225;0;225mcredentials\u001B[0m   \u001B]8;id=763694;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py\u001B\\\u001B[2mcredentials.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=33577;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py#1392\u001B\\\u001B[2m1392\u001B[0m\u001B]8;;\u001B\\\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> Found credentials in shared credentials file: ~<span style=\"color: #e100e1; text-decoration-color: #e100e1\">/.aws/credentials</span>   <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">credentials.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py#1392\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">1392</span></a>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'s3://nova-studio-output-data/sft/final/kssharda-sft-lora-lite-2-ui-run-2bn3c-<>8/output/model'\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-27T01:09:30.542741Z",
     "start_time": "2025-11-27T01:09:28.668735Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "bedrock_model_builder = BedrockModelBuilder(\n",
    "    model = training_job\n",
    ")\n",
    "\n",
    "bedrock_model_builder.deploy(job_name = \"nargokul-26-01\",\n",
    "                             custom_model_name = \"nargokul-26-01\",\n",
    "                             role_arn=\"arn:aws:iam::<>:role/Admin\")"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m[11/26/25 17:09:28]\u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m Found credentials in shared credentials file: ~\u001B[38;2;225;0;225m/.aws/\u001B[0m\u001B[38;2;225;0;225mcredentials\u001B[0m   \u001B]8;id=892830;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py\u001B\\\u001B[2mcredentials.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=908475;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py#1392\u001B\\\u001B[2m1392\u001B[0m\u001B]8;;\u001B\\\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[11/26/25 17:09:28] </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> Found credentials in shared credentials file: ~<span style=\"color: #e100e1; text-decoration-color: #e100e1\">/.aws/credentials</span>   <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">credentials.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/venv/lib/python3.12/site-packages/botocore/credentials.py#1392\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">1392</span></a>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m[11/26/25 17:09:29]\u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m S3 artifacts path:                                        \u001B]8;id=340743;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\u001B\\\u001B[2mbedrock_model_builder.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=618013;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#209\u001B\\\u001B[2m209\u001B[0m\u001B]8;;\u001B\\\n",
       "\u001B[2;36m                    \u001B[0m         s3:\u001B[38;2;225;0;225m/\u001B[0m\u001B[38;2;225;0;225m/nova-studio-output-data/sft/final/kssharda-sft-lora-\u001B[0m \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;225;0;225mlite-2-ui-run-2bn3c-<>8/output/\u001B[0m\u001B[38;2;225;0;225mmodel\u001B[0m            \u001B[2m                            \u001B[0m\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[11/26/25 17:09:29] </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> S3 artifacts path:                                        <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">bedrock_model_builder.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#209\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">209</span></a>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         s3:<span style=\"color: #e100e1; text-decoration-color: #e100e1\">//nova-studio-output-data/sft/final/kssharda-sft-lora-</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #e100e1; text-decoration-color: #e100e1\">lite-2-ui-run-2bn3c-<>8/output/model</span>            <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m                   \u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m Manifest path:                                            \u001B]8;id=541474;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\u001B\\\u001B[2mbedrock_model_builder.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=80220;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#216\u001B\\\u001B[2m216\u001B[0m\u001B]8;;\u001B\\\n",
       "\u001B[2;36m                    \u001B[0m         s3:\u001B[38;2;225;0;225m/\u001B[0m\u001B[38;2;225;0;225m/nova-studio-output-data/sft/final/kssharda-sft-lora-\u001B[0m \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;225;0;225mlite-2-ui-run-2bn3c-<>8/output/output/\u001B[0m\u001B[38;2;225;0;225mmanifest.\u001B[0m \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;225;0;225mjson\u001B[0m                                                      \u001B[2m                            \u001B[0m\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> Manifest path:                                            <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">bedrock_model_builder.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#216\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">216</span></a>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         s3:<span style=\"color: #e100e1; text-decoration-color: #e100e1\">//nova-studio-output-data/sft/final/kssharda-sft-lora-</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #e100e1; text-decoration-color: #e100e1\">lite-2-ui-run-2bn3c-<>8/output/output/manifest.</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #e100e1; text-decoration-color: #e100e1\">json</span>                                                      <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m                   \u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m Looking for manifest at                                   \u001B]8;id=356570;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\u001B\\\u001B[2mbedrock_model_builder.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=618595;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#223\u001B\\\u001B[2m223\u001B[0m\u001B]8;;\u001B\\\n",
       "\u001B[2;36m                    \u001B[0m         s3:\u001B[38;2;225;0;225m/\u001B[0m\u001B[38;2;225;0;225m/nova-studio-output-data/sft/final/kssharda-sft-lora-\u001B[0m \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;225;0;225mlite-2-ui-run-2bn3c-<>8/output/output/\u001B[0m\u001B[38;2;225;0;225mmanifest.\u001B[0m \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;225;0;225mjson\u001B[0m                                                      \u001B[2m                            \u001B[0m\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> Looking for manifest at                                   <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">bedrock_model_builder.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#223\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">223</span></a>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         s3:<span style=\"color: #e100e1; text-decoration-color: #e100e1\">//nova-studio-output-data/sft/final/kssharda-sft-lora-</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #e100e1; text-decoration-color: #e100e1\">lite-2-ui-run-2bn3c-<>8/output/output/manifest.</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #e100e1; text-decoration-color: #e100e1\">json</span>                                                      <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m                   \u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m Manifest content: \u001B[1m{\u001B[0m\u001B[38;2;0;135;0m'checkpoint_s3_bucket'\u001B[0m:                \u001B]8;id=291479;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\u001B\\\u001B[2mbedrock_model_builder.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=238165;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#229\u001B\\\u001B[2m229\u001B[0m\u001B]8;;\u001B\\\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;0;135;0m's3://customer-escrow-<>-smtj-3ff597fc/kssharda\u001B[0m \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;0;135;0m-sft-lora-lite-2-ui-run-2bn3c-<>8/step_4'\u001B[0m,      \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;0;135;0m'intermediate_checkpoints'\u001B[0m:                               \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[1m[\u001B[0m\u001B[38;2;0;135;0m's3://customer-escrow-<>-smtj-3ff597fc/ksshard\u001B[0m \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;0;135;0ma-sft-lora-lite-2-ui-run-2bn3c-<>8/step_3'\u001B[0m\u001B[1m]\u001B[0m\u001B[1m}\u001B[0m    \u001B[2m                            \u001B[0m\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> Manifest content: <span style=\"font-weight: bold\">{</span><span style=\"color: #008700; text-decoration-color: #008700\">'checkpoint_s3_bucket'</span>:                <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">bedrock_model_builder.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#229\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">229</span></a>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #008700; text-decoration-color: #008700\">'s3://customer-escrow-<>-smtj-3ff597fc/kssharda</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #008700; text-decoration-color: #008700\">-sft-lora-lite-2-ui-run-2bn3c-<>8/step_4'</span>,      <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #008700; text-decoration-color: #008700\">'intermediate_checkpoints'</span>:                               <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"font-weight: bold\">[</span><span style=\"color: #008700; text-decoration-color: #008700\">'s3://customer-escrow-<>-smtj-3ff597fc/ksshard</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #008700; text-decoration-color: #008700\">a-sft-lora-lite-2-ui-run-2bn3c-<>8/step_3'</span><span style=\"font-weight: bold\">]}</span>    <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001B[2;36m                   \u001B[0m\u001B[2;36m \u001B[0m\u001B[1;38;2;0;105;255mINFO    \u001B[0m Checkpoint URI:                                           \u001B]8;id=545156;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\u001B\\\u001B[2mbedrock_model_builder.py\u001B[0m\u001B]8;;\u001B\\\u001B[2m:\u001B[0m\u001B]8;id=779715;file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#236\u001B\\\u001B[2m236\u001B[0m\u001B]8;;\u001B\\\n",
       "\u001B[2;36m                    \u001B[0m         s3:\u001B[38;2;225;0;225m/\u001B[0m\u001B[38;2;225;0;225m/customer-escrow-<>-smtj-3ff597fc/kssharda-\u001B[0m \u001B[2m                            \u001B[0m\n",
       "\u001B[2;36m                    \u001B[0m         \u001B[38;2;225;0;225msft-lora-lite-2-ui-run-2bn3c-<>8/\u001B[0m\u001B[38;2;225;0;225mstep_4\u001B[0m         \u001B[2m                            \u001B[0m\n"
      ],
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span><span style=\"color: #0069ff; text-decoration-color: #0069ff; font-weight: bold\">INFO    </span> Checkpoint URI:                                           <a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">bedrock_model_builder.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///Users/nargokul/workspace/sagemaker-python-sdk-staging-1/sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py#236\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">236</span></a>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         s3:<span style=\"color: #e100e1; text-decoration-color: #e100e1\">//customer-escrow-<>-smtj-3ff597fc/kssharda-</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">                    </span>         <span style=\"color: #e100e1; text-decoration-color: #e100e1\">sft-lora-lite-2-ui-run-2bn3c-<>8/step_4</span>         <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">                            </span>\n",
       "</pre>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "{'ResponseMetadata': {'RequestId': '95bc35c0-0f8e-48cb-95e2-00fb77b17b4d',\n",
       "  'HTTPStatusCode': 202,\n",
       "  'HTTPHeaders': {'date': 'Thu, 27 Nov 2025 01:09:30 GMT',\n",
       "   'content-type': 'application/json',\n",
       "   'content-length': '88',\n",
       "   'connection': 'keep-alive',\n",
       "   'x-amzn-requestid': '95bc35c0-0f8e-48cb-95e2-00fb77b17b4d'},\n",
       "  'RetryAttempts': 0},\n",
       " 'modelArn': 'arn:aws:bedrock:us-east-1:<>:custom-model/imported/pl4keb8mfank'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from sagemaker.ai_registry.dataset import DataSet\n",
    "\n",
    "dataset = DataSet.get(name=\"arn:aws:sagemaker:us-east-1:<>:hub-content/MDG6N5CA58D0IJMC1OPJOPIKOS2VPPLP0AM6UBOT9D73B8A34HTG/DataSet/nova-2-0-sft-dataset/1.0.0\")\n",
    "\n",
    "pprint(dataset.__dict__)"
   ],
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
